package com.example.controller;

import com.example.common.Result;
import com.example.entity.Menu;
import com.example.entity.PageBean;
import com.example.entity.Worker;
import com.example.service.FileUploadService;
import com.example.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private FileUploadService fileUploadService;

    @GetMapping("/info")
    public Result getuMenuinfo(@RequestParam("menuname") String menuname)
    {
        Menu menu=menuService.findByMenuMname(menuname);
//        menu.setMenuImage(fileUploadService.getImageUrl(menu.getMenuImage()));
        return Result.success(menu);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Menu menu) {
        menuService.add(menu);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(@RequestParam("id") List<Integer> id) {
        menuService.delete(id);
        return Result.success();
    }

    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "5") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize, String menuname,String menuprice) {
        PageBean pageBean = menuService.page(page, pageSize, menuname, menuprice);
        return Result.success(pageBean);
    }
    @PutMapping("/updata")
    public Result updata(@RequestBody Menu menu){
        menuService.updata(menu);
        return Result.success();
    }

}
